package com.ocean.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ocean.admin.core.annotation.Log;
import com.ocean.admin.core.annotation.enums.BusinessType;
import com.ocean.admin.model.dto.operlog.SysOperLogQueryDTO;
import com.ocean.admin.model.vo.operlog.SysOperLogVo;
import com.ocean.admin.service.ISysOperLogService;
import com.ocean.core.util.response.ResultSet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author zhang
 * @since 2022-08-16
 */
@Tag(name = "系统日志管理")
@RestController
@RequestMapping("/admin/sys-oper-log")
public class SysOperLogController {

    @Autowired
    private ISysOperLogService iSysOperLogService;

    /**
     * 分页查询操作日志
     *
     * @param queryDTO 查询条件
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermission('system:operLog:pageList')")
    @Operation(summary = "分页查询操作日志")
    @PostMapping(value = "pageList")
    public ResultSet<IPage<SysOperLogVo>> pageList(@Validated @RequestBody SysOperLogQueryDTO queryDTO) {
        return ResultSet.ok(iSysOperLogService.pageList(queryDTO));
    }

    /**
     * 删除系统日志
     *
     * @param operIds 日志ID
     * @return 结果
     */
    @Operation(summary = "删除系统日志")
    @PreAuthorize("@ss.hasPermission('system:operLog:removeOperLog')")
    @Log(title = "系统日志管理", businessType = BusinessType.DELETE)
    @GetMapping(value = "removeOperLog/{operIds}")
    public ResultSet<String> removeOperLog(@PathVariable Long[] operIds) {
        return ResultSet.ok(iSysOperLogService.removeOperLog(operIds));
    }
}
